package com.mvp.shq.washer.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;


import com.google.gson.Gson;
import com.mvp.shq.washer.entity.User;

/**
 * Created by Administrator on 2016/4/5.
 */
public class SpUtil {
    static SharedPreferences prefs;

    public static void init(Context context) {
        prefs = PreferenceManager.getDefaultSharedPreferences(context);
    }


    public static User getUser() {
        return new Gson().fromJson(prefs.getString("user", ""), User.class);
    }

    public static void setUser(User user) {
        prefs.edit().putString("user", new Gson().toJson(user)).commit();
    }
    public static String getToken(){
        return prefs.getString("token","");
    }
    public static void setToken(String token){
        prefs.edit().putString("token",token).commit();
    }
    public static boolean isFirst(){
        return prefs.getBoolean("isFirst",true);
    }
    public static void setFirst(boolean isFirst){
        prefs.edit().putBoolean("isFirst",isFirst).commit();
    }
    public static void setLongData(String key, long value){
        prefs.edit().putLong(key,value).commit();
    }
    public static long getLongData(String key){
        return prefs.getLong(key,-1);
    }
    public static int getUnReadNum(){
        return prefs.getInt("unReadNum",0);
    }
    public static void setUnReadNum(int num){
        prefs.edit().putInt("unReadNum",num).commit();
    }


}
